import React from "react";
import store from "../redux/store";

import { connect} from 'react-redux'

function count(props) {
  //  console.log(props);
    return (
      <div>
        <h1>我是count组件，我要使用redu中的数据</h1>
        <div>{props.shuibian}</div>
        <button
          onClick={() => {
            props.dispatch({ type: "ADD", num: -5 });
          }}
        >
          -5
        </button>
        <button
          onClick={() => {
            props.dispatch({ type: "ADD", num: 5 });
          }}
        >
          +5
        </button>
      </div>
    );
}

// 获取数据
function mapStateToProps(state) {
  // console.log(state);
  return {
    'shuibian':state.count,
  }
}



const withCount = connect(mapStateToProps)(count);
export default withCount;
